<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>递归函数</title>
</head>
<body>
    
    <script>
    
        {
            // 没有限制条件的递归是耍流氓
            //递归函数  求和

            function fn(n){
                if(n<0) return 0;
                return n + fn(n-1);
            }

            console.log(fn(5));


            function gn (m) {
                if (m<=0) return 1;
                return m*gn(m-1);
            }

            console.log(gn(3));

        
        }

        {
            function func( n )
            {
                if (n == 0 || n == 1)
                {
                    return 1;
                }
                return func(n-1) + func(n-2);
            }

            var a = func(22);
            console.log(a);

        }

        
    </script>

</body>
</html>